package org.example;

public class Test1 {
    //leetcode 134 加油站 https://leetcode.cn/problems/gas-station/description/?envType=study-plan-v2&envId=top-interview-150
    public int canCompleteCircuit(int[] gas, int[] cost) {
        int totalTank = 0,pathTank = 0,index = 0;
        for (int i = 0; i < gas.length; i++) {
            int dev = gas[i] - cost[i];
            totalTank += dev;
            pathTank += dev;
            if (pathTank < 0) {
                index = i + 1;
                pathTank = 0;
            }
        }
        return totalTank >= 0 ? index : -1;
    }

    public static void main(String[] args) {
        Test1 test1 = new Test1();
        int[] gas = {1,2,3,4,5};
        int[] cost = {3,4,5,1,2};
        test1.canCompleteCircuit(gas,cost);
        System.out.println(555);
    }
}
